package com.example.appointment.controller;

import com.example.appointment.common.Result;
import com.example.appointment.dto.UserDTO;
import com.example.appointment.dto.UserLoginDTO;
import com.example.appointment.dto.UserRegisterDTO;
import com.example.appointment.service.UserService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/auth")
@RequiredArgsConstructor
public class AuthController {
    private final UserService userService;

    @PostMapping("/register")
    public Result<UserDTO> register(@Valid @RequestBody UserRegisterDTO registerDTO) {
        return Result.success(userService.register(registerDTO));
    }

    @PostMapping("/login")
    public Result<UserDTO> login(@Valid @RequestBody UserLoginDTO loginDTO) {
        return Result.success(userService.login(loginDTO));
    }

    @PostMapping("/logout")
    public Result<Void> logout() {
        userService.logout();
        return Result.success();
    }

    @GetMapping("/current-user")
    public Result<UserDTO> getCurrentUser() {
        return Result.success(userService.getCurrentUserDTO());
    }
} 